<template>
	<view class="detail" v-if="detail">
		<scroll-view scroll-y="true" class="main">
			<view class="swiperBox">
				<u-swiper :list="detail.images" height="550rpx"></u-swiper>
			</view>
			<view class="title">{{detail.name}}</view>
			<view class="numBox">
				<view class="num"><text class="icon">¥</text>{{detail.price}}</view>服务报酬
			</view>
			<view class="line">
				<view class="icon"></view>
				<view class="l">预约时间：</view>
				<view class="r">{{detail.starttime |date('yyyy年mm月dd日')}}</view>
			</view>
			<view class="line">
				<view class="icon"></view>
				<view class="l">所需人数：</view>
				<view class="r">{{detail.surplusnum}}人</view>
			</view>
			<view class="address">
				<image src="../../static/index/address.png" class="icon" mode=""></image>
				<view class="l">雇主位置：</view>
				<view class="r">{{detail.address}}</view>
			</view>
			<view class="descT">服务描述</view>
			<view class="desc">
				{{detail.content}}
			</view>
			<view class="notice">
				<image src="../../static/index/notice.png" class="bg" mode=""></image>
				<view class="con">
					<view class="l">温馨提示：</view>
					<view class="r" v-html="info"></view>
				</view>
			</view>
		</scroll-view>
		<view class="record" @click="play" v-if="detail.file">
			<image src="../../static/index/stop.png" class="icon" mode="" v-if="stop"></image>
			<image src="../../static/index/doing.png" class="icon" mode="" v-else></image>
			<view class="word" v-if="stop">播放</view>
			<view class="word" v-else>停止</view>
		</view>
		<view class="btn" v-if="detail.count > 0" @click="show = true">已接单</view>
		<view class="btn" v-else @click="report">电话联系</view>
		<u-popup :show="show" @close="show = false" @open="show = true" mode="center" round="20">
			<view class="user">
				<image src="../../static/logo.png" class="avatar" mode=""></image>
				<view class="name">{{detail.username}}</view>
				<view class="tel">联系电话：{{detail.mobile}}</view>
				<view class="info">联系对方时，请告知对方，我们是从哪个平台上看到的</view>
				<view class="btns" @click="tel">拨打</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	const innerAudioContext = uni.createInnerAudioContext();
	innerAudioContext.autoplay = true;
	export default {
		data() {
			return {
				show: false,
				detail: '',
				info: '',
				stop: true
			};
		},
		onLoad(options) {
			console.log(options)
			this.getDetail(options.id)
			this.getInfo()
			
			let that = this
			innerAudioContext.onEnded(()=>{
				that.stop = true
				recorderManager.stop()
			})
		},
		methods:{
			play() {
				
				if(this.detail.file){
					if(this.stop){
						this.stop = false
						innerAudioContext.src = this.oss(this.detail.file);
						innerAudioContext.play();
					} else {
						this.stop = true
						innerAudioContext.pause();
					}
					
				}
			},
			tel() {
				uni.$u.http.post('/mobilelog',{
					mobile:this.detail.mobile
				}).then(res => {
					if (res.code == 1) {
						uni.makePhoneCall({
							phoneNumber: this.detail.mobile
						});
					}
				}).catch((res) => {
				
				})
			},
			report() {
				this.tel()
				return
				if (!uni.getStorageSync('token')) {
					uni.$u.route({
						url: 'pagesA/auth/login'
					})
					return
				}
				uni.$u.http.post('/citydetail', {
					id: this.detail.id,
					type: 'accept'
				}).then(res => {
					if (res.code == 1) {
						this.detail.count = 1
						// this.$u.toast(res.msg);
						this.show = true
					}
				}).catch((res) => {
				
				})
			},
			getInfo() {
				uni.$u.http.post('/getconfig', {
					type:11
				}).then(res => {
					if (res.code == 1) {
						// this.info = res.data.config.map((value) => {
						// 	return this.oss(value)
						// })
						res.data.config = res.data.config.replace(/<img/g,
							"<img style='max-width:100%;height:auto'")
						this.info = res.data.config
					}
				}).catch((res) => {
				
				})
			},
			getDetail(id) {
				uni.$u.http.post('/citydetail', {
					id: id
				}).then(res => {
					if (res.code == 1) {
						if(res.data.images){
							res.data.images = res.data.images.map((value) => {
								return this.oss(value)
							})
						} else {
							res.data.images = []
						}
						
						this.detail = res.data
					}
				}).catch((res) => {
				
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	// page {
	// 	height: 100%;
	// }

	.detail {
		height: 100vh;
		position: relative;
		.record{
			position: absolute;
			left: 319rpx;
			bottom: 200rpx;
			width: 112rpx;
			height: 112rpx;
			background: linear-gradient(to bottom, #95C0FF, #428DFC);
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			border-radius: 50%;
			z-index: 1000;
			.icon{
				width: 36rpx;
				height: 40rpx;
			}
			.word{
				color: #FFFFFF;
				font-size: 24rpx;
			}
		}
		.main {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			bottom: 120rpx;
		}

		.btn {
			background: linear-gradient(to right, #FFDF41, #FFC141);
			height: 88rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 32rpx;
			color: #191615;
			border-radius: 44rpx;
			width: 590rpx;
			position: absolute;
			left: 80rpx;
			bottom: 20rpx;
			flex-shrink: 0;
		}
		.user{
			width: 520rpx;
			height: 540rpx;
			border-radius: 30rpx;
			background-color: #FFFFFF;
			display: flex;
			flex-direction: column;
			align-items: center;
			padding: 0 50rpx;
			box-sizing: border-box;
			.avatar{
				width: 170rpx;
				height: 170rpx;
				border-radius: 50%;
				border-radius: 50%;
				margin-top: -80rpx;
				margin-bottom: 20rpx;
			}
			.name{
				color: #191615;
				font-size: 36rpx;
				margin-bottom: 20rpx;
			}
			.tel{
				color: #191615;
				font-size: 30rpx;
				margin-bottom: 20rpx;
			}
			.info{
				background-color: #FFFAE5;
				border: 10rpx;
				padding: 20rpx;
				color: #FF8007;
				font-size: 22rpx;
				margin-bottom: 40rpx;
			}
			.btns{
				background: linear-gradient(to right, #FFDF41, #FFC141);
				display: flex;
				align-items: center;
				justify-content: center;
				width: 400rpx;
				height: 72rpx;
				color: #191615;
				font-size: 30rpx;
				border-radius: 36rpx;
			}
		}

		.title {
			padding: 40rpx 40rpx 10rpx;
			border-radius: 40rpx 40rpx 0 0;
			margin-top: -40rpx;
			z-index: 10000;
			position: relative;
			background-color: #fff;
			color: #191615;
			font-size: 40rpx;
			font-weight: bold;
		}

		.numBox {
			display: flex;
			align-items: center;
			padding: 0 40rpx;
			color: #999999;
			font-size: 24rpx;

			.num {
				color: #FF5B1A;
				font-size: 44rpx;
				margin-right: 10rpx;

				.num {
					font-size: 30rpx;
				}
			}
		}

		.line {
			display: flex;
			align-items: center;
			padding: 10rpx 40rpx;

			.icon {
				width: 9rpx;
				height: 35rpx;
				background: linear-gradient(to right, #FFC141, #FFDF41);
				border-radius: 0 9rpx 9rpx 0;
			}

			.l {
				color: #999999;
				font-size: 28rpx;
				margin: 0 0 0 20rpx;
			}

			.r {
				color: #575859;
				font-size: 28rpx;
			}
		}

		.address {
			display: flex;
			padding: 0 40rpx;
			align-items: flex-start;

			.icon {
				width: 20rpx;
				height: 27rpx;
				margin-top: 10rpx;
				margin-right: 10rpx;
			}

			.l {
				color: #575859;
				font-size: 28rpx;
				flex-shrink: 0;
			}

			.r {
				color: #575859;
				font-size: 28rpx;
			}
		}

		.descT {
			color: #191615;
			font-size: 34rpx;
			padding: 20rpx 40rpx 0;
		}

		.desc {
			color: #575859;
			font-size: 28rpx;
			line-height: 40rpx;
			padding: 0 40rpx;
		}

		.notice {
			width: 600rpx;
			margin: 20rpx 40rpx;
			position: relative;

			.bg {
				position: absolute;
				left: 0;
				top: 0;
				width: 100%;
				height: 100%;
				z-index: 10;
			}

			.con {
				position: relative;
				z-index: 1000;
				display: flex;
				align-items: flex-start;
				width: 100%;
				padding: 20rpx;
				box-sizing: border-box;

				.l {
					flex-shrink: 0;
					font-size: 26rpx;
					color: #FF8007;
					margin-right: 10rpx;
				}

				.r {
					color: #FF8007;
					font-size: 26rpx;
				}

			}
		}
		
	}
</style>
